package com.eva.databuilder.enums;

import com.eva.databuilder.builders.AbstractTemplateDataBuilder;
import com.eva.databuilder.builders.cms.*;
import com.eva.databuilder.builders.demo.DemoBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum TemplateDataBuilderConfigEnum {

    ARTICLE_DETAIL("ARTICLE_DETAIL", ArticleDetailBuilder.class, Boolean.FALSE, "文章详情"),
    CATEGORIES_TREE("CATEGORIES_TREE", CategoryTreeBuilder.class, Boolean.TRUE,"栏目树"),
    SUB_CATEGORIES_TREE("SUB_CATEGORIES_TREE", SubCategoryTreeBuilder.class, Boolean.FALSE,"子栏目树"),
    MULTIPLE_CATEGORY_ARTICLE_PAGE("MULTIPLE_CATEGORY_ARTICLES", MultipleCategoryArticlesBuilder.class, Boolean.FALSE,"多栏目文章列表数据"),
    MULTIPLE_RESOURCES("MULTIPLE_RESOURCES", MultipleResourceListBuilder.class, Boolean.FALSE,"多资源组资源列表"),
    ARTICLE_PAGE("ARTICLE_PAGE", ArticlePageBuilder.class, Boolean.FALSE,"查询文章分页数据"),
    SEARCH_PAGE("SEARCH_PAGE", SearchPageBuilder.class, Boolean.FALSE,"站内搜索分页数据"),

    // 示例
    DEMO("DEMO", DemoBuilder.class, Boolean.FALSE,"示例数据构建器"),
    ;

    @ApiModelProperty("数据项编码")
    private final String code;

    @ApiModelProperty("数据项构建器")
    private final Class<? extends AbstractTemplateDataBuilder<?>> builder;

    @ApiModelProperty("是否启用缓存")
    private final Boolean enabledCache;

    @ApiModelProperty("备注")
    private final String remark;

    /**
     * 根据数据项编码获取配置
     *
     * @param code 数据项编码
     * @return TemplateDataBuilderConfigEnum
     */
    public static TemplateDataBuilderConfigEnum getByCode (String code) {
        for (TemplateDataBuilderConfigEnum item : values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }
}
